﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>考场管理</title>
    <link href="../css/main.css" rel="stylesheet" type="text/css" />
    <link href="../css/Jqbox.css" rel="stylesheet" type="text/css" />
    <script src="../js/jquery-1.5.2.min.js" type="text/javascript"></script>
    <script src="../js/ligerui.min.js" type="text/javascript"></script>
    <script src="../Js/jquery.dialog.js" type="text/javascript"></script>
    <script src="../Js/conmon.js" type="text/javascript"></script>
    <script type="text/javascript"> 
　　   //获得参数的方法
        var request = {
            QueryString: function (val) {
                var uri = window.location.search;
                var re = new RegExp("" + val + "=([^&?]*)", "ig");
                return ((uri.match(re)) ? (uri.match(re)[0].substr(val.length + 1)) : null);
            }
        }

        var $grid;
        var maiheight = 500;
        var vUrl = null;
        var modelID = -1;
        var menu = null;
        var tree = null;

        $(function () {
            maiheight = $(window).height();

            $("#layout1").ligerLayout({ leftWidth: 170, heightDiff: -0 });
            $("#txtBeginDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd" });
            $("#txtEndDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd" });
            //获取参数
            if (request.QueryString("modelID") != null)
                modelID = request.QueryString("modelID");
            //显示gride
            $grid = $("#maingrid").ligerGrid({
                columns: [
               { display: '序号', align: 'left', width: 40, type: 'int', isSort: false,
                   render: function (item, i) {
                       i = i + 1;
                       return i;
                   }
               },
                { display: '考场名称', name: 'E_Name', align: 'left', width: 150 },
                { display: '参考职务', name: 'rolename', align: 'left', width: 220 },
                { display: '开始日期', name: 'BeginStr', width: 80 },
                { display: '结束日期', name: 'EndStr', width: 80 },
                { display: '考试时长', name: 'E_Time', width: 60, render: function (item) { return item.E_Time + "分钟" } },
                { display: '应考人数', name: 'YKRS', width: 60 },
                { display: '实考人数', name: 'SkRS', width: 60,
                    render: function (item) {
                        return "<a href='javascript:' onclick='jmp_exam_member(" + item.E_ID + ",\"" + item.E_Name + "\");' >" + item.SkRS + " (人) </a>";
                    }
                },
                { display: '创建日期', name: 'E_Date', dateFormat: "yyyy-MM-dd", width: 80 },
                { display: '状态', name: 'E_Status', isSort: false, width: 60,
                    render: function (item) {
                        if (item.E_Status == 0) return "√";
                        else if (item.E_Status == 1) return "×";
                    }
                },
                { display: '停/启用', name: 'E_ID', isSort: false, width: 70,
                    render: function (item) {
                        if (item.E_Status == 0)
                            return "<a onclick='SetExamSatus(" + item.E_ID + ",1);' href='javascript:' >停用</a>";
                        else if (item.E_Status == 1)
                            return ("<a onclick='SetExamSatus(" + item.E_ID + ",0);' href='javascript:' >启用</a>&nbsp;&nbsp;" +
                                  "<a onclick='DeleteExam(" + item.E_ID + ",\"" + item.E_Name + "\");' href='javascript:' >删除</a>");
                    }
                }],
                parms: [
                       { name: 'areID', value: $("#Aid").val() },
                       { name: 'modelID', value: modelID },
                       { name: 'beginDate', value: $("#txtBeginDate").val() },
                       { name: 'endDate', value: $("#txtEndDate").val() },
                       { name: 'name', value: $("#txtTitle").val() },
                       { name: 'status', value: $("#lstStatus").val() }
                ],
                dataAction: 'server', pageSize: 20,
                url: '../WebServer/ExamRoom.ashx?Action=ExamList&rnd=' + Math.random(),
                width: '100%', height: '95%', dateFormat: 'yyyy-MM-dd',
                onDblClickRow: function (data, rowindex, rowobj) {
                    $selectRow = data;
                    ShowDialog("ExamMng/examchart.htm", "图表", 750, 400);
                }
            });
            loadTree();

            menu = $.ligerMenu({
                top: 100,
                left: 100,
                width: 120,
                items: [
						{ text: '导出-考场列表', value: 'list', click: itemclick },
						{ text: '导出-成绩列表', value: 'score', click: itemclick }
					]
            });

            $("#export").click(function (e) {
                menu.show({ top: e.pageY, left: e.pageX });
                return false;
            });
        });

        // 导出
        function itemclick(item, i) {

            if (item.value == "score") {
                var RowData = $grid.getSelectedRow();
                if (null != RowData) {
                    exportUrl = "../WebServer/DownloadExcel.ashx?Action=ExportExamInfo&examid=" + RowData.E_ID;
                    window.open(exportUrl, "_blank");
                }
                else {
                    showErrorTip("请选中需要导出的考场.");
                }
            }
            else {  // 导出考场列表 
                exportUrl = "../WebServer/DownloadExcel.ashx?Action=ExportExamTable"
                + "&areID=" + $("#Aid").val()
                + "&modelID=" + modelID
                + "&beginDate=" + $("#txtBeginDate").val()
                + "&endDate=" + $("#txtEndDate").val()
                + "&name=" + $("#txtTitle").val()
                + "&status=" + $("#lstStatus").val();
                window.open(exportUrl, "_blank");
            }
        }

        function DeleteExam(examid,examname) {
            jqConfirm("删除考场将会删除该考场的参考记录,确认删除[" + examname + "]考场吗?", "删除考场", function (action) {
                if (action == "ok") {
                    var pars = { examid: examid };
                    $("layout1").mask("数据处理中，请稍候......");
                    $.post('../WebServer/ExamRoom.ashx?Action=delexam', pars, function (data) {
                        $("layout1").unmask();
                        var rdata = eval("(" + data + ")");
                        if (rdata.IsSuccess == 1) {
                            showAlertOk("删除考场[ " + examname + " ] 成功.");
                            loadGrid();
                        } else {
                            showErrorTip("删除考场[ " + examname + " ] 失败.");
                        }
                    });
                }
            });
        }

        function loadTree() {
            tree = $("#Orgtree").ligerTree({
                checkbox: false,
                slide: false,
                nodeWidth: 100,
                url: '../WebServer/MainAdmin.ashx?Action=AreaTree&rnd=' + Math.random(),
                onSelect: function (node) {
                    if (node.data.id) {
                        modelID = -1;
                        $("#Aid").val(node.data.id);
                        $("#txtBeginDate").val("");
                        $("#txtEndDate").val("");
                        $("#txtTitle").val("");
                        $("#lstStatus").val(-1);
                        loadGrid();
                    }
                }
            });
        }
        function Search() {
            var node = tree.getSelected();
            if (node == null) {
                $("#Aid").val("-1");
            }
            loadGrid();
        }

        // 跳转考场人员
        function jmp_exam_member(examid, examname) {
            parent.window.jmp_exam_member(examid, examname);
        }

        function loadGrid() {
            if (!$grid) return;
            $("tbody > tr", $grid.gridbody).each(function () {
                $(this).remove();
            });
            $grid.setOptions({ parms: [
                                { name: 'areID', value: $("#Aid").val() },
                                { name: 'modelID', value: modelID }, 
                                { name: 'beginDate', value: $("#txtBeginDate").val() },
                                { name: 'endDate', value: $("#txtEndDate").val() },
                                { name: 'name', value: $("#txtTitle").val() }, 
                                { name: 'status', value: $("#lstStatus").val() }
                ], newPage: 1, Rows: [], Total: 0
            });   //设置数据参数
            $grid.loadData(true); //加载数据
        }

        //修改考场状态
        function SetExamSatus(id, status) {
            $("#layout1").mask("数据处理中，请稍候......");
            var params = { ExamID: id, Status: status, Rnd: Math.random() };
            $.post('../WebServer/ExamRoom.ashx?Action=SetExamStatus', params, function (msgData) {
                var data = eval("(" + msgData + ")");
                $("#layout1").unmask();
                if (data.IsSuccess == 1) {
                    loadGrid();
                    //$grid.loadData(true); //加载数据
                    showAlertOk("操作成功！");
                }
                else
                    showErrorTip("操作失败，请重试！");
            });
        }
    </script>

     <style type="text/css"> 
 
            body{ padding:5px; margin:0; padding-bottom:15px;}
            #layout1{  width:100%;margin:0; padding:0;  }  
            .l-page-top{ height:80px; background:#f8f8f8; margin-bottom:3px;}
            h4{ margin:20px;}
  </style>
</head>
<body style="padding:10px">
    <div id="layout1">
        <div position="left" title="">
            <ul id="Orgtree">
            </ul>
        </div>
        <!-- end-->
        <div position="center" title="">
            <table border="0" cellspacing="0" cellpadding="0" width="100%">
			    <tr>
				    <td style="background: #E5EDEF; padding-left:5px; padding-top: 3px;" width="80">起始日期:</td>
				    <td style="background: #E5EDEF; padding-left:5px; padding-top: 3px;" width="120"><input id="txtBeginDate" type="text" /></td>
				
				    <td style="background: #E5EDEF; padding-left:5px; padding-top: 3px;" width="80">考场名称:</td>
				    <td style="background: #E5EDEF; padding-left:5px;" width="120"><input id="txtTitle" type="text" class="l-text" /></td>
				
				    <td rowspan="2" style="background: #E5EDEF; padding-left:5px;" width="80"><div class="l-button" style="width: 60px; height:35px; padding-top:11px;" onclick="Search()">查寻</div></td>
				
				    <td rowspan="2" style="background: #E5EDEF; padding-left:5px;"><div id="export" class="l-button" style="width: 80px; height:35px; padding-top:11px;">考场导出</div></td>
			    </tr>
			    <tr>
				    <td style="background: #E5EDEF; padding-left:5px; padding-top: 3px;" width="80">结束日期:</td>
				    <td style="background: #E5EDEF; padding-left:5px; padding-top: 3px;" width="120"><input id="txtEndDate" type="text" /></td>
				
				    <td style="background: #E5EDEF; padding-left:5px; padding-top: 3px;" width="80">考场状态</td>
				    <td style="background: #E5EDEF; padding-left:5px; padding-top: 3px;" width="120">
                        <select id="lstStatus" style="width:135px;">
                            <option value="-1" title="全部" selected="selected">全部</option>
                            <option value="0">启用</option>
                            <option value="1">停用</option>
                        </select>
                    </td>
			    </tr>
		    </table>
            <div id="maingrid"></div>
        </div>
    </div>
    <input type="hidden" id="Aid" value="-1" />
</body>
</html>
